package com.affablebean.model.bll;

import java.sql.SQLException;
import java.util.List;

import com.affablebean.model.dal.AbstractDAL;
import com.affablebean.model.entity.GenericEntity;

public abstract class AbstractBLL<E extends GenericEntity> {

	private AbstractDAL<E> abstractDAL;

	public AbstractBLL(AbstractDAL<E> abstractDAL) {
		this.abstractDAL = abstractDAL;
	}

	public boolean insertEntity(E entity) throws SQLException {
		boolean result = false;
		if (validateEntity(entity)) result = abstractDAL.insertEntity(entity);
		return result;
	}

	public boolean updateEntity(E entity) throws SQLException {
		boolean result = false;
		if (validateEntity(entity)) result = abstractDAL.updateEntity(entity);
		return result;
	}

	public boolean deleteEntity(E entity) throws SQLException {
		return abstractDAL.deleteEntity(entity);
	}

	public List<E> getAll() throws SQLException {
		return abstractDAL.getAll();
	}

	public E findById(int id) throws SQLException {
		return abstractDAL.findById(id);
	}

	public int getCount() throws SQLException {
		return abstractDAL.getCount();
	}

	abstract boolean validateEntity(E entity);

}
